package com.cdtu.labpreview.controller;

import com.cdtu.labpreview.common.Result;
import com.cdtu.labpreview.common.UserHolder;
import com.cdtu.labpreview.dto.UserDTO;
import com.cdtu.labpreview.entity.Feeling;
import com.cdtu.labpreview.entity.InstrumentIntroduction;
import com.cdtu.labpreview.mapper.BaseIntroductionMapper;
import com.cdtu.labpreview.service.IFeelingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 心得体会模块
 */
@RestController
@RequestMapping("/feeling")
public class FeelingController {

    @Autowired
    private IFeelingService feelingService;



    /**
     * 查看心得体会列表
     * @return
     */
    @GetMapping("/list")
    public Result getFeelingList(){
        UserDTO userDTO = UserHolder.getUser();
        int no = userDTO.getUserNo();
        int type = userDTO.getType();
        return feelingService.getFeelingList(no,type);
    }
    /**
     * 老师根据id查看心得体会
     * @return
     */
    @GetMapping("/teacher/{id}")
    public Result getFeelingById(@PathVariable("id") long id){
        return feelingService.getFeelingById(id);
    }

    /**
     * 学生根据id提交心得体会
     * @param feeling
     * @return
     */
    @PostMapping
    public Result addFeeling(@RequestBody Feeling feeling){
        UserDTO userDTO = UserHolder.getUser();
        int sno = userDTO.getUserNo();
        return feelingService.addFeeling(feeling,sno);
    }

    /**
     * 修改心得体会（老师）
     * @param feeling
     * @return
     */
    @PutMapping
    public Result updateFeeling(@RequestBody Feeling feeling){
        return feelingService.updateFeeling(feeling);
    }

    /**
     * 删除心得体会（老师）
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteFeeling(@PathVariable("id") long id){
        return feelingService.deleteFeeling(id);
    }
}
